﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMaterial" :model="stateMaterial.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialCode_FormItem" prop="Entity.MaterialCode" :label="$t('message.autotrans._Model_Material_MaterialCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Material_MaterialCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateMaterial.vmModel.Entity.MaterialCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialType_FormItem" prop="Entity.MaterialType" :label="$t('message.autotrans._Model_Material_MaterialType')">
            <el-input v-model="stateMaterial.vmModel.Entity.MaterialType" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialName_FormItem" prop="Entity.MaterialName" :label="$t('message.autotrans._Model_Material_MaterialName')">
            <el-input v-model="stateMaterial.vmModel.Entity.MaterialName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialVersion_FormItem" prop="Entity.MaterialVersion" :label="$t('message.autotrans._Model_Material_MaterialVersion')">
            <el-input v-model="stateMaterial.vmModel.Entity.MaterialVersion" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MeasureUnitCode_FormItem" prop="Entity.MeasureUnitCode" :label="$t('message.autotrans._Model_Material_MeasureUnitCode')">
            <el-input v-model="stateMaterial.vmModel.Entity.MeasureUnitCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Regular_FormItem" prop="Entity.Regular" :label="$t('message.autotrans._Model_Material_Regular')">
            <el-input v-model="stateMaterial.vmModel.Entity.Regular" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ShipRegular_FormItem" prop="Entity.ShipRegular" :label="$t('message.autotrans._Model_Material_ShipRegular')">
            <el-input v-model="stateMaterial.vmModel.Entity.ShipRegular" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MachineStatus_FormItem" prop="Entity.MachineStatus" :label="$t('message.autotrans._Model_Material_MachineStatus')">
            <el-select v-model="stateMaterial.vmModel.Entity.MachineStatus" clearable>
               <el-option key="CREATED" value="CREATED" :label="$t('message.autotrans._Enum_BaseStatus_CREATED')"></el-option>
               <el-option key="USED" value="USED" :label="$t('message.autotrans._Enum_BaseStatus_USED')"></el-option>
               <el-option key="FORBIDDEN" value="FORBIDDEN" :label="$t('message.autotrans._Enum_BaseStatus_FORBIDDEN')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitMaterial"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseMaterial"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationMaterialEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { materialApi } from '/@/api/baseinformation/material';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMaterial = ref();
const stateMaterial = reactive({
    vmModel: {
	  Entity:{
        MaterialCode: '',
        MaterialType: '',
        MaterialName: '',
        MaterialVersion: '',
        MeasureUnitCode: '',
        Regular: '',
        ShipRegular: '',
        MachineStatus: undefined,
        ID:null,
      },

	},
    
});

// 取消
const onCloseMaterial = () => {
    closeDialog();
};

// 提交
const onSubmitMaterial = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMaterial.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            materialApi().edit(stateMaterial.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
	})
};

// 页面加载时
onMounted(() => {
    
    if (ci.attrs["wtmdata"]) {
		stateMaterial.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMaterial.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	materialApi().get(stateMaterial.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateMaterial.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

